package com.allwees.bs.c.module.product.service;

import com.allwees.bs.c.module.product.dto.MarketingInfo;
import com.allwees.bs.c.module.product.dto.ProductDetailsDTO;
import com.allwees.bs.c.module.product.dto.ProductReviewDTO;
import com.allwees.bs.c.module.product.dto.SkuCheckDTO;
import com.allwees.bs.c.module.product.dto.SkuCheckResult;
import com.allwees.bs.c.module.product.dto.SkuDTO;
import com.allwees.bs.c.module.product.entity.ProductEntity;
import com.allwees.bs.core.model.constant.CacheName;
import com.allwees.bs.core.modelbase.page.PageParams;
import com.allwees.bs.core.modelbase.page.PaginateDTO;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

public interface ProductService {

	/**
	 * 首页搜索商品
	 *
	 * @param keyword 查询关键字
	 * @return 商品
	 */
	@Cacheable(cacheNames = CacheName.PROD_SEARCH_KEY_PAGE,
			key = "T(String).valueOf(#keyword).concat('-').concat(#pageParams.size).concat(',').concat(#pageParams.current)")
	PaginateDTO<ProductDetailsDTO> search(String keyword, PageParams pageParams);

	/**
	 * 商品分类列表获取
	 *
	 * @param categoryNo 商品分类
	 * @param pageParams 翻页参数
	 * @return 商品分页列表对象
	 */
	@Cacheable(cacheNames = CacheName.PROD_CATEGORY_PAGE,
			key = "T(String).valueOf(#categoryNo).concat('-').concat(#pageParams.size).concat(',').concat(#pageParams.current)")
	PaginateDTO<ProductDetailsDTO> getCategoryProducts(String categoryNo, PageParams pageParams);

	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_BY_UUID, key = "#productUuid", unless = "#result == null")
	ProductDetailsDTO findProductByUuid(String productUuid);

	@Cacheable(cacheNames = CacheName.PROD_SKU_BY_UUID, key = "#skuUuid", unless = "#result == null")
	SkuDTO findSkuByUuid(String skuUuid);

	/**
	 * 获取商品详情
	 *
	 * @param productUuid 商品信息
	 * @return 商品
	 */
	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_DETAILS, key = "#productUuid",unless = "#result.status != 0")
	ProductDetailsDTO getProductDetails(String productUuid);

	/**
	 * 获取商品的相关商品
	 *
	 * @param productUuid 商品ID
	 * @param size 数据条数
	 * @return 标准翻页商品
	 */
	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_RELATED, key = "T(String).valueOf(#productUuid).concat('-').concat(#size)")
	List<ProductDetailsDTO> getRelatedProducts(String productUuid, int size);

	/**
	 * 获取商品的评论列表
	 *
	 * @param productUuid 商品ID
	 * @param current 当前页
	 * @return
	 */
	ProductReviewDTO getProductReviews(String productUuid, int current);


	PaginateDTO<ProductDetailsDTO> search4RefreshTask(String keywords, PageParams pageParams);

	PaginateDTO<ProductDetailsDTO> queryCategoryProduct4RefreshTask(String categoryNo, PageParams pageParams);

	/**
	 * 收藏和购买标记
	 * @param products
	 * @param userUuid
	 * @return
	 */
	List<ProductDetailsDTO> collectedOrBought(List<ProductDetailsDTO> products, String userUuid);

	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_HOTS, key = "T(String).valueOf(#marketingType).concat('-').concat(#pageParams.size).concat(',').concat(#pageParams.current)",sync = true)
	PaginateDTO<ProductDetailsDTO> findMarketingProducts(int marketingType, PageParams pageParams);

	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_FLASH, key = "T(String).valueOf(#pageParams.size).concat('-').concat(#pageParams.current)",sync = true)
	PaginateDTO<ProductDetailsDTO> flashProducts(PageParams pageParams,int marketingDay);

	/**
	 * 查询$5以下的商品
	 * @param pageParams
	 * @return
	 */
	@Cacheable(cacheNames = CacheName.PROD_PRODUCT_BELOW5, key = "T(String).valueOf(#pageParams.size).concat('-').concat(#pageParams.current)",sync = true)
	PaginateDTO<ProductDetailsDTO> below5Products(PageParams pageParams);

	/**
	 * 根据用户的uuid查询其购物车内是否含有free gift类型商品
	 * @param userUuid
	 * @return
	 */
	List<ProductEntity> freeGiftsInOnesCart(String userUuid);

	/**
	 * 获取商品的marketing type 属性
	 * @param productUuid
	 * @return
	 */
	MarketingInfo getMarketingInfo(String productUuid);

	/**
	 * 购物车sku校验
	 * 1.商品是否有效
	 * 2.库存是否足够
	 * @param skus
	 * @return
	 */
	SkuCheckResult checkSku(List<SkuCheckDTO> skus);

	/**
	 * 增加库存
	 * @param skuUuid
	 * @param addend
	 * @return
	 */
	@CachePut(cacheNames = CacheName.PROD_SKU_BY_UUID, key = "#skuUuid")
	SkuDTO addInventory(String skuUuid,int addend);

	/**
	 * 减少库存
	 * @param skuUuid
	 * @param minus
	 * @return
	 */
	@CachePut(cacheNames = CacheName.PROD_SKU_BY_UUID, key = "#skuUuid")
	SkuDTO decInventory(String skuUuid, int minus);

}
